//出库申请
import axios from "./axios";
import qs from 'qs'

export function getStockOutApplicationList({
                                               belongModule,
                                               applicationNumber,
                                               customer,
                                               pageNum,
                                               status,
                                               pageSize = 100
                                           }) {
    return axios.post('/stock_out_application/manage/stock_out_application_record_list.do', qs.stringify({
        belongModule,
        status,
        applicationNumber,
        customer,
        pageNum,
        pageSize
    })).then(res => Promise.resolve(res.data))
}

export function getStockOutApplicationListWithoutPage({
                                                          belongModule,
                                                      }) {
    return axios.post('/stock_out_application/manage/show_un_stock_out_apply.do',qs.stringify({belongModule})).then(res => Promise.resolve(res.data))
}

//增加出库申请
export function addStockOutApplication({
                                           supplier,
                                           requestBy,
                                           receiver,
                                           applicationNumber,
                                           customer,
                                           applicationDateStr,
                                           belongModule,
                                           stockOutApplicationDetailList
                                       }) {
    return axios.post('/stock_out_application/manage/add_stock_out_application_record.do', qs.stringify({
        supplier,
        requestBy,
        receiver,
        applicationNumber,
        customer,
        applicationDateStr,
        belongModule,
        stockOutApplicationDetailList
    })).then(res => Promise.resolve(res.data))
}

//修改出库申请
export function updateStockOutApplication({
                                              id,
                                              supplier,
                                              requestBy,
                                              receiver,
                                              applicationNumber,
                                              customer,
                                              applicationDateStr,
                                              belongModule,
                                              stockOutApplicationDetailList
                                          }) {
    return axios.post('/stock_out_application/manage/update_stock_out_application_record.do', qs.stringify({
        id,
        supplier,
        requestBy,
        receiver,
        applicationNumber,
        customer,
        applicationDateStr,
        belongModule,
        stockOutApplicationDetailList
    })).then(res => Promise.resolve(res.data))
}

//出库申请详情
export function stockOutApplicationDetail(id) {
    return axios.get('/stock_out_application/manage/show_stock_out_application_record_detail.do?id=' + id)
        .then(res => Promise.resolve(res.data))
}

export function deleteApply(id) {
    return axios.post('/stock_out_application/manage/delete_stock_out_application_record.do', qs.stringify({id}))
        .then(res => Promise.resolve(res.data))
}


export function createStockNo(stockOutDate) {
    return axios.post('/optimization_inventory/manage/create_stock_out_num.do', qs.stringify({stockOutDate})).then(res => Promise.resolve(res.data))
}

export function getStockOutList({customer, pageNum, warehouse, belongModule, stockOutNo, stockOutStatus}) {
    return axios.post('/optimization_inventory/manage/stock_out_list.do', qs.stringify({
        pageNum,
        warehouse,
        belongModule,
        stockOutNo,
        customer,
        stockOutStatus
    })).then(res => Promise.resolve(res.data))
}

export function getStockWorkNo() {
    return axios.get('/optimization_inventory/manage/select_work_no.do').then(res => Promise.resolve(res.data))
}

export function getStockOutDetail(stockOutId) {
    return axios.post('/optimization_inventory/manage/stock_out_detail.do', qs.stringify({stockOutId})).then(res => Promise.resolve(res.data))
}


export function stockOut({stockOutNum, applyId, stockOutDateStr, applyType, workOrderNo, salesOrderNum, stockOutDetails, customer, receiver, id, warehouse, belongModule}) {
    const data = qs.stringify({
        applyId,
        stockOutNum,
        stockOutDateStr,
        id,
        applyType,
        workOrderNo,
        salesOrderNum,
        stockOutDetails,
        customer,
        warehouse,
        receiver,
        belongModule
    });
    return axios.post('/optimization_inventory/manage/stock_out.do', data).then(res => Promise.resolve(res.data))
}

export function saveStockOut({stockOutNum, applyId, stockOutDateStr, applyType, workOrderNo, salesOrderNum, stockOutDetails, customer, receiver, id, warehouse, belongModule}) {
    const data = qs.stringify({
        applyId,
        stockOutNum,
        id,
        stockOutDateStr,
        applyType,
        workOrderNo,
        salesOrderNum,
        stockOutDetails,
        customer,
        warehouse,
        receiver,
        belongModule
    });
    return axios.post('/optimization_inventory/manage/save_stock_out_record.do', data).then(res => Promise.resolve(res.data))
}

//删除出库
export function deleteStockOut(stockOutId) {
    return axios.post('/optimization_inventory/manage/delete_stock_out_record.do', qs.stringify({stockOutId})).then(res => Promise.resolve(res.data))
}

//获取归还入库中的stock out num
export function getStockoutSelectList(belongModule, stockOutDate) {
    return axios.post('/optimization_inventory/manage/show_stock_out_param_list.do', qs.stringify({
        belongModule,
        stockOutDate
    })).then(res => Promise.resolve(res.data))
}

export function getStockOutRecord(stockOutId) {
    return axios.post('/optimization_inventory/manage/show_stock_out_detail.do', qs.stringify({stockOutId})).then(res => Promise.resolve(res.data))
}

//  IEC获取出库单号的接口
export function getStockOutNo() {
    return axios.get('/stock_change_record/show_record_list_by_iec.do').then(res => Promise.resolve(res.data))
}
// 获取出库信息
export function getStockOutInfo(stockOut) {
    return axios.post('/optimization_inventory/manage/show_all_stock_out_by_parts_id.do',qs.stringify(stockOut)).then(res => Promise.resolve(res.data))
}